<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude">

<xi:include href="master.html" />
<head>
    <meta content="text/html; charset=UTF-8" http-equiv="content-type" py:replace="''"/>
    <title>Trainer</title>
    <style type="text/css">
        input[type="text"]{width:30px;}
        #info{text-align:right;padding-left:50px;font-weight:bold;font-size:14px;}
    </style>
    <script type="text/javascript">
    //<![CDATA[
    var anncreated = ${1 if ann else 0};
    function createann(){
        showSpinner();
        new Request.JSON({url:'createann',onSuccess:function(r){
            if (r.created){
                var s = '<p id="anninfo">An ANN is created with '+$('inputs').value
                +' inputs, '+$('hiddenlayer').value+' hidden layers and '+$('outputs').value+' outputs.</p>';
                $('create').parentNode.innerHTML = s;
                anncreated = 1;
            }
            hideSpinner();
        }}).get({'inputs':$('inputs').value, 'hidden': $('hiddenlayer').value, 'outputs': $('outputs').value});
    }
    function train(){
        if (!anncreated){
            alert('You have to create an ANN first.');
            return;
        }
        showSpinner();
        new Request.JSON({url:'trainann',onSuccess:function(r){
            $('epochs').innerHTML = r.epochs;
            $('errorrate').innerHTML = r.errorrate;
            hideSpinner();
        }}).get({'times':$('times').value});
    }
    function loadnet(){
    }
    function savenet(){
    }
    //]]>
    </script>
</head>
<?python
  # define mock menus as list of (title, url, is_active) tuples
  menu_top = [
    ('Home','/',False),
    ('Faces','/photofilter', False),
    ('ANN','/anntrainer', True),
    ('SVM','/svmtrainer', False)
  ]
  menu_side = [
    ('Official Website', 'http://www.turbogears.org'),
    ('Documentation', 'http://docs.turbogears.org'),
    ('Bugs & Suggestions', 'http://trac.turbogears.org'),
    ('Mailing List', 'http://groups.google.com/group/turbogears'),
  ]
?>
<body>
    <h1>ANN trainer</h1>
    <table>
        <tr>
            <td>
                <h2> Create ANN </h2>
                <form id="create" method="post" action="createann" onsubmit="createann(); return false;" py:if="not ann">
                    Create an Artificial Neural Network with <input type="text" id="inputs" value="19" /> inputs, 
                    <input type="text" id="hiddenlayer" value="20" /> hidden layers and
                    <input type="text" id="outputs" value="1" /> outputs.
                    <input type="submit" value="Create" />
                </form>
                <p py:if="ann" id="anninfo">An ANN is created with ${ann.inputs} inputs, ${ann.hidden} hidden layers and ${ann.outputs} outputs.</p>
            </td>
            <td id="info">
                <p>Epochs: <span id="epochs">${ann.times if ann else 0}</span></p>
                <p>Error rate: <span id="errorrate">${ann.errorrate if ann else 'N/A'}</span></p>
            </td>
        </tr>
        <tr><td colspan="2">
                <h2> Load </h2>
                <form method="post" action="loadnet" onsubmit="loadnet(); return false;">
                    Load net: 
                    <select id="nets">
                        <option py:for="n in nets" value="${n.id}">${n.getFile()}</option>
                    </select>
                    <input type="submit" value="Load" />
                </form>
            </td>
        </tr>
        <tr><td colspan="2">
            <h2>Train</h2>
                <form method="post" action="train" onsubmit="train(); return false;">
                    Train <input type="text" id="times" value="1" /> times, now. <input type="submit" value="Train" />
                </form>
            </td>
        </tr>
        <tr><td colspan="2">
            <h2>Save</h2>
                <form method="post" action="savenet" onsubmit="savenet(); return false;">
                    Save current net configuration with name <input id="netname" /><input type="submit" value="Save" />
                </form>
            </td>
        </tr>
    </table>
</body>
</html>
